Testing basic functions of Motion Clouds

  |   Source

Motion Clouds: raw principles

Motion Clouds are synthesized textures which aim at having similar characteristics as natural images but with controlled parameters. There are many ways to achieve these results and this notebook aims at showing that different procedures from different communities (neurioscience, modelling, computer vision, ...) may produce similar results.

In [6]:
import numpy as np
np.set_printoptions(precision=3, suppress=True)
import pylab
import matplotlib.pyplot as plt
%matplotlib inline
  Hide output
In [7]:
def show_video(filename):
    from IPython.display import display, Image, HTML
    from base64 import b64encode
    video = open(mc.figpath + filename + mc.vext, "rb").read()
    video_encoded = b64encode(video)
    video_tag = '<video controls  autoplay="autoplay" loop="loop" width=350px src="data:video/x-m4v;base64,{0}">'.format(video_encoded)
    display(HTML(data=video_tag))
  Hide output

Using Fourier ("official Motion Clouds")

In [8]:
import sys
sys.path.append('..')
import MotionClouds as mc
fx, fy, ft = mc.get_grids(mc.N_X, mc.N_Y, mc.N_frame)
  Hide output

Using mixtures of images

In [9]:
import scipy.misc
lena = scipy.misc.lena() * 1.
lena -= lena.mean()
lena /= lena.std()
print lena.shape
  Hide output
(512, 512)

In [11]:
plt.imshow(lena, cmap=plt.cm.gray)
  Hide output
Out[11]:
<matplotlib.image.AxesImage at 0x104fdb450>
In [12]:
def noise(image=lena):
    for axis in [0, 1]:
        image = np.roll(image, np.random.randint(image.shape[axis]), axis=axis)
    return image
  Hide output
In [13]:
plt.imshow(noise(), cmap=plt.cm.gray)
  Hide output
Out[13]:
<matplotlib.image.AxesImage at 0x104f7bc50>
In [14]:
plt.imshow(noise(), cmap=plt.cm.gray)
  Hide output
Out[14]:
<matplotlib.image.AxesImage at 0x104ff2d90>

Using ARMA processes

Now, we define the ARMA process as an averaging process with a certain time constant $\tau=30.$ (in frames).

In [15]:
def ARMA(image, tau=30.):
    image = (1 - 1/tau)* image + 1/tau * noise()
    return image
  Hide output

initializing

In [17]:
image = ARMA(lena)
plt.imshow(image, cmap=plt.cm.gray)
  Hide output
Out[17]:
<matplotlib.image.AxesImage at 0x106d75990>
In [18]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
  Hide output
Out[18]:
<matplotlib.image.AxesImage at 0x1076aff90>
In [19]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
  Hide output
Out[19]:
<matplotlib.image.AxesImage at 0x107d66490>
In [20]:
for _ in range(1000): image = ARMA(image)
plt.imshow(image, cmap=plt.cm.gray)
  Hide output
Out[20]:
<matplotlib.image.AxesImage at 0x107d98950>
In [21]:
N_frame = 1024
z = np.zeros((lena.shape[0], lena.shape[1], N_frame))
z[:, :, 0] = image
for i_frame in range(1, N_frame): 
    z[:, :, i_frame] = ARMA(z[:, :, i_frame-1])
mc.anim_save(.5 + .5*z, filename='results/arma')
  Hide output
calculating  99% |############################################# | ETA:  0:00:00
Saving sequence results/arma.mp4

calculating 100% |##############################################| Time: 0:00:58

In [22]:
show_video(filename='arma')
  Hide output
In []:
 
  Hide output
Comments powered by Disqus
    Share